home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / gnu / a2_0bEmacs_bin.lha / Emacs-19.25 / etc / sh.c < prev    next >
C/C++ Source or Header  |  1993-05-09  |  1KB  |  72 lines

  1. #include <exec/types.h>
  2. #include <dos/dostags.h>
  3. #include <stdio.h>
  4.  
  5. #include <proto/dos.h>
  6.  
  7. int execute(char *cmd)
  8. {
  9.     long rc;
  10.  
  11.     while (*cmd == ' ') cmd++;
  12.     if (strncmp(cmd, "exec", 4) == 0 && (cmd[4] == ' ' || cmd[4] == '\t')) cmd += 4;
  13.     if ((rc = SystemTags(cmd, SYS_UserShell, TRUE, TAG_END)) == -1)
  14.     {
  15.     fprintf(stderr, "Failed to execute command %s\n", cmd);
  16.     return 20;
  17.     }
  18.     return rc;
  19. }
  20.  
  21. void main(int argc, char **argv)
  22. {
  23.   int command;
  24.   char *command_string;
  25.   char *program_name = argv[0];
  26.   struct RDArgs *args;
  27.   long opts[1];
  28.   static char options[] = "";
  29.  
  30.   /* Throw out AmigaDOS args so that Input() is clean */
  31.   if (args = ReadArgs(options, opts, NULL)) FreeArgs(args);
  32.  
  33.   command = 0;
  34.   /* Simplistic argument parsing */
  35.   argv++;
  36.   argc--;
  37.   while (argc > 0 && argv[0][0] == '-')
  38.     {
  39.       switch (argv[0][1])
  40.     {
  41.     case 'c':
  42.       if (argc == 1) goto usage;
  43.       command = 1;
  44.       command_string = argv[1];
  45.       argv++;
  46.       argc--;
  47.       break;
  48.     case 'i': case'v':
  49.       /* ignored for now */
  50.       break;
  51.     default: goto usage;
  52.     }
  53.       argc--;
  54.       argv++;
  55.     }
  56.   if (argc != 0) goto usage;
  57.  
  58.   if (command) exit(execute(command_string));
  59.   else exit(Execute("", Input(), NULL) ? 0 : 1);
  60.  
  61.  usage:
  62.   fprintf(stderr, "%s [-i] [-c command]\n", program_name);
  63.   exit(1);
  64. }
  65.  
  66.  
  67. /*
  68.  * Local variables:
  69.  * compile-command: "lc -L -v sh.c"
  70.  * end:
  71.  */
  72.